home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 992 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.6 KB  |  82 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: jdmorris@ix.netcom.com (Jason D. Morris)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Must exception classes have copy constructors?
  5. Date: 06 Apr 1996 11:33:58 PST
  6. Organization: Netcom
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <3165fcc3.2177561@nntp.ix.netcom.com>
  9. References: <606373375wnr@ma.ccngroup.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Sat, 06 Apr 1996 05:11:45 GMT
  12. X-NETCOM-Date: Fri Apr 05  9:10:50 PM PST 1996
  13. X-Newsreader: Forte Agent .99d/32.182
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBVAwUBMWbHJ0y4NqrwXLNJAQFLdAIAzXl2DYLHV/c36+Ty7qCRDbYFjEyC9WSl
  16.     S3zQTwMI1jk8Eoz2tfmTvKGLmX+QCCaBBg0lSogV5Zh617nRg14VLA==
  17.     =+omO
  18. Originator: austern@isolde.mti.sgi.com
  19.  
  20. On 05 Apr 96 02:58:28 GMT, Alan Griffiths <aGriffiths@ma.ccngroup.com>
  21. wrote:
  22.  
  23. >I've just tried porting some code to MSVC4 (it compiles and works with 
  24. >SC7.1 and BC4.5).
  25. >
  26. >In effect it appears that the Microsoft compiler _requires_ anything 
  27. >thrown as an exception to have an accessible copy constructor.  (I've 
  28. >tended to make copy constructors private to ensure catch-by-reference
  29. >and aviod slicing bugs.)
  30. >
  31. >Looking through the DWP I can't see any reason to require a copy 
  32. >constructor, but there are references to copying temporaries.
  33. >
  34. >Is MSVC4 correct?
  35. >
  36. >code:
  37. >class MyBaseException {
  38. >public:  MyBaseException() {}
  39. >         virtual char* what() = 0;
  40. >private: MyBaseException(const MyBaseException&);
  41. >};
  42. >
  43. >class MyException1 : public  MyBaseException {
  44. >public:     virtual char* what() { return "MyException1"; }
  45. >};
  46. >
  47. >int main() {
  48. >    try     {
  49. >        throw MyException1();
  50. >// error C2700: 'class MyException1' : cannot be thrown (use -W4 for more info)
  51. >
  52. >// warning C4671: 'MyException1' : the copy constructor is inaccessible
  53. >    } catch (MyBaseException& e) {
  54. >        cout << "OK - got here (" << __LINE__ << ") : have a " << e.what()
  55. >        << endl;
  56. >    } catch (...) {
  57. >        cout << "ERROR - got here (" << __LINE__ << ")" << endl;
  58. >    }
  59. >    return 0;
  60. >}
  61. >
  62.  
  63. Here's what BC++ 5.0 generates...
  64.  
  65. Borland C++ 5.0 for Win32 Copyright (c) 1993, 1996 Borland
  66. International
  67. MS-EXCPT.CPP:
  68. Error MS-EXCPT.CPP 15: Compiler could not generate copy constructor
  69. for class 'MyException1' in function main()
  70. *** 1 errors in Compile ***
  71.  
  72. It appears we have an agreement in interpretation of the DWP.
  73.  
  74. Jason
  75. ---
  76. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  77.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  78.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  79.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  80.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  81. ]
  82.